/*
 * Copyright 2009-2010 the original author or authors.
 *
 * Licensed under the Apache license, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.internna.iwebjtracker.server.scm.model;

import java.util.Date;
import org.internna.iwebjtracker.project.model.IWebJTrackerUser;
import org.internna.iwebjtracker.project.model.Module;
import org.internna.iwebjtracker.project.model.Project;
import org.internna.iwebjtracker.project.model.Version;
import org.internna.iwebjtracker.server.connection.ConnectionDetails;

/**
 * Represents all the information relative to one item in the SCM server.
 *
 * @author Jose Noheda
 * @since 1.0
 */
public interface ItemInfo<C extends ConnectionDetails, M extends Module<P, M>, V extends Version<U, P, V>, U extends IWebJTrackerUser, P extends Project<C, M, V, U, P>> {

    /**
     * Usually an item exists if there's information available but it may not be the case for all servers.
     *
     * @return true if the item is there in the repository.
     */
    boolean exists();

    /**
     * Absolute path (beginning at project root) where you can find this item.
     *
     * @return a string formatted by this type of server to find some item.
     */
    String getAbsolutePath();

    /**
     * Mime type suitable to be used as Conten-Type in a client transfer.
     *
     * @return a known mime type (server side).
     */
    String getMimeType();

    /**
     * Time when this item was involved in a commit for the last time.
     *
     * @return a non-null date.
     */
    Date getLastModified();

    /**
     * Time when this item was created for the first time.
     *
     * @return a non-null date.
     */
    Date getCreation();

    /**
     * Size of the file in bytes.
     *
     * @return a positive integer if size is available. -1 otherwise.
     */
    long getSizeInBytes();

    /**
     * The message the developer left when committing the changeset that included this item.
     *
     */
    String getLastCommitMessage();

    /**
     * The username of the SCM developer who committed the changeset that included this item.
     */
    String getLastCommitUser();

    /**
     * The file contents stored in the SCM server.
     *
     * @return null if it wasn't loaded previously. Otherwise the binary or text data.
     */
    ItemData getData();

    /**
     * Sets the contents retrieved from the server.
     *
     */
    void setData(ItemData data);

    /**
     * Checks if this item is a container for other items.
     *
     * @return true if this item correspond to a folder in the SCM.
     */
    boolean isDirectory();

    /**
     * Returns the project this item info belongs to.
     *
     * @return a non null project object
     */
    P getProject();

}
